import router from "./router"

export default () => {
	//白名单中放登陆后才可访问的页面，根据isLogin判断是否放行
	let whiteList = [
		"/my",
		"/my/dynamicresources",
		"/my/myInformation",
		"/myvip",
		"/room",
		"/room/myroom",
		"/room/store",
		"/room/history",
		"/discuss",
		"/center",
	]
	router.beforeEach((to, from, next) => {
		let res = whiteList.find((item) => item == to.path)
		if (res) {
			let isLogin = localStorage.getItem("isLogin")
			if (isLogin != "yes") {
				next({ name: "home" })
			} else {
				next()
			}
			//自动登录功能：如果没有尝试自动发送请求，如果已经过期则进入到登陆页面
		} else {
			next()
		}
	})
}
